package com.zjw.shortlink.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjw.shortlink.project.common.convention.result.Result;
import com.zjw.shortlink.project.common.convention.result.Results;
import com.zjw.shortlink.project.dto.req.ShortLinkGroupStatsAccessRecordReqDTO;
import com.zjw.shortlink.project.dto.req.ShortLinkGroupStatsReqDTO;
import com.zjw.shortlink.project.dto.req.ShortLinkStatsAccessRecordReqDTO;
import com.zjw.shortlink.project.dto.req.ShortLinkStatsReqDTO;
import com.zjw.shortlink.project.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import com.zjw.shortlink.project.dto.resp.ShortLinkStatsRespDTO;
import com.zjw.shortlink.project.service.ShortLinkStatsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ShortLinkStatsController {
    private final ShortLinkStatsService shortLinkStatsService;

    @PostMapping("/api/short-link/v1/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(@RequestBody ShortLinkStatsReqDTO requestParams) {
        return Results.success(shortLinkStatsService.oneShortLinkStats(requestParams));
    }

    @PostMapping("/api/short-link/v1/stats/access-record")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(@RequestBody ShortLinkStatsAccessRecordReqDTO requestParam) {
        return Results.success(shortLinkStatsService.shortLinkStatsAccessRecord(requestParam));
    }

    @PostMapping("/api/short-link/v1/stats/group")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(@RequestBody ShortLinkGroupStatsReqDTO requestParam) {
        return Results.success(shortLinkStatsService.groupShortLinkStats(requestParam));
    }

    @PostMapping("/api/short-link/v1/stats/access-record/group")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(@RequestBody ShortLinkGroupStatsAccessRecordReqDTO requestParam) {
        return Results.success(shortLinkStatsService.groupShortLinkStatsAccessRecord(requestParam));
    }
}
